package com.kaishengit.web;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.File;
import com.kaishengit.entity.FileType;
import com.kaishengit.entity.User;
import com.kaishengit.service.FileService;
import com.kaishengit.service.FileTypeService;
import com.kaishengit.service.UserService;
import com.kaishengit.util.DateTimeUtil;
import com.kaishengit.util.web.ServletUtil;

public class fileNew extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		FileTypeService filetypeService = new FileTypeService();
		UserService userService = new UserService();
		
		List<FileType> fileTypeList = new FileTypeService().findAll();
		List<User> userList = new UserService().findAll();
		request.setAttribute("fileTypeList",fileTypeList);
		request.setAttribute("userList",userList);
		
		ServletUtil.forword(request, response,"fileshare/new_file");
		
		
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {

		
		Map<String,String> map = ServletUtil.upLoadFile(request);
	
		String filename =map.get("filename");
		String filesize = map.get("filesize");
		
		String name = map.get("name");
		String filetypeId = map.get("filetypeId");
		String userId = map.get("userId");
		//DateTimeUtil.getNew();
		
		
		File file = new File();
		
		
		file.setFilename(filename);
		
		file.setName(name);
		file.setFilesize(Long.parseLong(filesize));
		file.setFiletypeid(filetypeId);
		file.setUserid(userId);
		
		
		 new FileService().save(file);
		
		ServletUtil.forword(request, response, "fileshare/file");
		
		
		
		
		
		
	}
}